/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import { closeCollect, closeBrandCollect } from '@/services/exWarehouseRatio';
import { optionsTypes, optionsUrls } from '../config/index';
import { message } from 'antd';

const handleDisable = ({ cm_id, options, data, actionRef, brand, cb }: any) => {
  let optionsType = {};
  if (options == 0) {
    optionsType = { [optionsTypes[options]]: 0 };
  } else if (options == 1) {
    optionsType = { [optionsTypes[options]]: brand };
  } else if (options == 2) {
    optionsType = { [optionsTypes[options]]: 1 };
  }
  closeCollect({
    data,
    cm_id,
    ...optionsType,
    url: optionsUrls[options],
  }).then((res) => {
    const { code, msg } = res;
    if (code == 0) {
      if (cb && typeof cb === 'function') cb();
      actionRef.current?.reload(false);
      message.success(msg);
    } else {
      message.error(msg);
    }
  });
};

function handleCollection({
  is_close,
  cm_id,
  phone,
  brand,
  actionRef,
}: {
  is_close: number;
  cm_id: string;
  phone: string;
  brand: string;
  actionRef: any;
}) {
  closeBrandCollect({ is_close, brand, cm_id, phone, admin_sms: 0 }).then((res) => {
    const { code, msg } = res;
    if (code == 0) {
      actionRef.current?.reload();
      message.success(msg);
    } else {
      message.error(msg);
    }
  });
}

export { handleDisable, handleCollection };
